"use strict";
const uniCloudRouter = require("uni-cloud-router");
const utils = require("utils");
const config = require("./config.js");
const router = new uniCloudRouter.Router(config);
function getFunctionErr(message) {
  if (utils.util.nilValue(message)) {
    return new utils.BaseErr(-70001, "未知错误");
  }
  if (message instanceof utils.BaseErr) {
    return message;
  }
  return new utils.InsideErr(message);
}
exports.main = async (event, context) => {
  try {
    let result = await router.serve(event, context);
    let { code, message } = result || {};
    if (!utils.util.nilValue(code) && code !== 0) {
      return utils.util.resErr(getFunctionErr(message));
    } else {
      return result;
    }
  } catch (e) {
    let error = new utils.InsideErr(e);
    return utils.util.resErr(error);
  }
};
